rm(list = ls())
library(ggplot2)
library(tidyverse)
library(readstata13)

df1 <- read.dta13("statements_coef1.dta")
df2 <- read.dta13("statements_coef2.dta")
df3 <- read.dta13("statements_coef3.dta")
df4 <- read.dta13("statements_coef4.dta")
df5 <- read.dta13("statements_coef5.dta")
df6 <- read.dta13("statements_coef6.dta")


df1$lower <- df1$coef - (1.96*df1$se)
df1$upper <- df1$coef + (1.96*df1$se)
df2$lower <- df2$coef - (1.96*df2$se)
df2$upper <- df2$coef + (1.96*df2$se)
df3$lower <- df3$coef - (1.96*df3$se)
df3$upper <- df3$coef + (1.96*df3$se)
df4$lower <- df4$coef - (1.96*df4$se)
df4$upper <- df4$coef + (1.96*df4$se)
df5$lower <- df5$coef - (1.96*df5$se)
df5$upper <- df5$coef + (1.96*df5$se)
df6$lower <- df6$coef - (1.96*df6$se)
df6$upper <- df6$coef + (1.96*df6$se)

#Figure 1a
p3 <- ggplot()
p3 <- p3 + geom_point(aes(x=order, y=coef), color="darkblue", data=df3, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:3, minor_breaks = NULL, labels=c("10","100","1,000"))
p3 <- p3 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df3, width = 0.2)
p3 <- p3 + ylab("Predicted Annual Statements Per Ally-Year") + xlab("GDP (billions USD), log scale") + scale_y_continuous(breaks=c(-.1,-0.05,0,0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5,.55,.6,.65,.7,.75,.8,.85,.9,.95,1), minor_breaks = NULL)
p3 <- p3 + geom_line(aes(x=order, y=coef), color="darkblue", data=df3, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p3



#Figure 1b
p4 <- ggplot()
p4 <- p4 + geom_point(aes(x=order, y=coef), color="darkblue", data=df4, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:2, minor_breaks = NULL, labels=c("No","Yes"))
p4 <- p4 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df4, width = 0.2)
p4 <- p4 + ylab("Predicted Annual  Statements Per Ally-Year") + xlab("Nuclear Latency") + scale_y_continuous(breaks=c(0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5), minor_breaks = NULL)
p4 <- p4 + geom_smooth(aes(x=order, y=coef), method="lm", color="darkblue", data=df4, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p4


#Figure 1c
p5 <- ggplot()
p5 <- p5 + geom_point(aes(x=order, y=coef), color="darkblue", data=df5, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:2, minor_breaks = NULL, labels=c("No","Yes"))
p5 <- p5 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df5, width = 0.2)
p5 <- p5 + ylab("Predicted Annual Statements Per Ally-Year") + xlab("Nuclear Weapons") + scale_y_continuous(breaks=c(0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5,.55,.6,.65,.7,.75,.8), minor_breaks = NULL)
p5 <- p5 + geom_smooth(aes(x=order, y=coef), method="lm", color="darkblue", data=df5, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p5


#Figure 1d
p6 <- ggplot()
p6 <- p6 + geom_point(aes(x=order, y=coef), color="darkblue", data=df6, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:4, minor_breaks = NULL, labels=c("0","1","2","3"))
p6 <- p6 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df6, width = 0.2)
p6 <- p6 + ylab("Predicted Annual Statements Per Ally-Year") + xlab("Adversary Support") + scale_y_continuous(breaks=c(0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5), minor_breaks = NULL)
p6 <- p6 + geom_line(aes(x=order, y=coef), color="darkblue", data=df6, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p6



#Figure 1e
p1 <- ggplot()
p1 <- p1 + geom_point(aes(x=order, y=coef), color="darkblue", data=df1, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:5, minor_breaks = NULL, labels=c("0","10","100","1,000","10,000"))
p1 <- p1 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df1, width = 0.2)
p1 <- p1 + ylab("Predicted Annual Statements Per Ally-Year") + xlab("US War Casualties (3-yr average), log scale") + scale_y_continuous(breaks=c(0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5), minor_breaks = NULL)
p1 <- p1 + geom_line(aes(x=order, y=coef), color="darkblue", data=df1, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p1


#Figure 1f
p2 <- ggplot()
p2 <- p2 + geom_point(aes(x=order, y=coef), color="darkblue", data=df2, size=3, na.rm = TRUE) + scale_x_continuous(breaks = 1:7, minor_breaks = NULL, labels=c("-1","0","1","2","3","4","5"))
p2 <- p2 + geom_errorbar(aes(x=order, ymin = lower, ymax = upper), color="darkblue", data=df2, width = 0.2)
p2 <- p2 + ylab("Predicted Annual Statements Per Ally-Year") + xlab("US GDP Growth") + scale_y_continuous(breaks=c(0.05,.1,.15,.2,.25,.3,.35,.4,.45,.5), minor_breaks = NULL)
p2 <- p2 + geom_line(aes(x=order, y=coef), color="darkblue", data=df2, size=0.5) +theme(axis.title=element_text(size=12,face="bold"))
p2
